package com.awspaas.user.apps.processforsap.util;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.emm.util.DateUtil;
import com.actionsoft.sdk.local.SDK;

import java.util.Date;

/**
 * @program: universal-interface
 * @author: hust
 * @create: 2024-07-10 15:58
 * @des：
 **/
public class Logs {

    /**
     * @param interfaceName 接口名称
     * @param interfaceNo   接口编码
     * @param interfaceType 接口类型
     * @param send          发送方
     * @param receive       接收方
     * @param inParameter   请求入参
     * @param outParameter  请求出参
     * @param isSuccess     接口调用是否成功
     * @param code          业务代码
     * @param isProcess     启动流程
     * @param processId     流程版本ID
     */
    public static void addLog(String interfaceName, String interfaceNo, String interfaceType, String send
            , String receive, String inParameter, String outParameter, boolean isSuccess, String code, String isProcess, String processId, String msg,String logId) {

        BO logBo = new BO();
        logBo.setId(logId);
        logBo.set("INTERFACE_NAME",interfaceName);
        logBo.set("INTERFACE_NO",interfaceNo);
        logBo.set("URL",interfaceNo);
        logBo.set("INTERFACE_TYPE",interfaceType);
        logBo.set("SEND",send);
        logBo.set("RECEIVE",receive);
        logBo.set("LOG_TIME",DateUtil.format(new Date(),DateUtil.DATETIME_DFT_PATTERN));
        logBo.set("IN_PARAMETER",inParameter);
        logBo.set("OUT_PARAMETER",outParameter);
        logBo.set("IS_SUCCESS",isSuccess);
        logBo.set("CODE",code);
        logBo.set("IS_PROCESS",isProcess);
        logBo.set("PROCESS_ID",processId);
        logBo.set("MSG",msg);
        ProcessInstance processInstance = SDK.getProcessAPI().createProcessInstance("obj_6d4682d5cb2c4e4f8feaef94d531b2df","admin","接口日志");
        SDK.getBOAPI().create("BO_EU_SERVICE_LOG",logBo,processInstance,UserContext.fromUID("admin"));
    }

    /**
     * 更新
     * @param logId
     */
    public static void updateLog(String inParameter, String outParameter,String logId) {
        inParameter = inParameter.replace("'","\"");
        outParameter = outParameter.replace("'","\"");
        String updateSql = "update BO_EU_SERVICE_LOG set IN_PARAMETER='"+inParameter+"',OUT_PARAMETER='"+outParameter+"' where id='"+logId+"'";
        DBSql.update(updateSql);
    }
}
